package com.hopu.v1.controller.admin.verify;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hopu.v1.pojo.common.PageData;
import com.hopu.v1.pojo.common.R;
import com.hopu.v1.pojo.question.Questions;
import com.hopu.v1.service.admin.verify.VerifyQuestionsService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import java.io.Serializable;
import java.util.List;

/**
 * 题目表(Questions)表控制层
 *
 * @author makejava
 * @since 2024-09-29 16:34:45
 */
@RestController
@RequestMapping("/api/v1/admin/verify/questions")
@CrossOrigin
public class VerifyQuestionsController {
    /**
     * 服务对象
     */
    @Resource
    private VerifyQuestionsService questionsService;

    /**
     * 分页查询所有数据
     *
     * @param page 分页对象
     * @param questions 查询实体
     * @return 所有数据
     */
    @GetMapping
    public R selectAll(Page<Questions> page, Questions questions) {
        return R.ok(this.questionsService.page(page, new QueryWrapper<>(questions)));
    }

    /**
     * 分页查询所有
     * @param currentPage
     * @param pageSize
     * @return
     */
    @GetMapping("/selectAll")
    public R selectAll(Integer currentPage, Integer pageSize,String status) {
        PageData<Questions> subjectPageData = questionsService.selectAll(currentPage, pageSize,status);
        return R.ok("数据获取成功",subjectPageData);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public R selectOne(@PathVariable Serializable id) {
        return R.ok(this.questionsService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param questions 实体对象
     * @return 新增结果
     */
    @PostMapping
    public R insert(@RequestBody Questions questions) {
        return R.ok(this.questionsService.save(questions));
    }

    /**
     * 修改数据
     *
     * @param questions 实体对象
     * @return 修改结果
     */
    @PutMapping
    public R update(@RequestBody Questions questions) {
        return R.ok(this.questionsService.updateById(questions));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    public R delete(@RequestParam("idList") List<Long> idList) {
        return R.ok(this.questionsService.removeByIds(idList));
    }
}

